import "package:flutter/material.dart";
import "../type.dart";
import "./DynamicImageListWidget.dart";
import "./DynamicVideoWidget.dart";
import "./DynamicArticleWidget.dart";

// 动态列表
class DynamicShareItemWidget extends StatelessWidget {
  final DynamicShareItem dynamicShareItem;
  const DynamicShareItemWidget({
    super.key,
    required this.dynamicShareItem,
  });
  @override
  Widget build(BuildContext context) {
    DynamicUPInfo dynamicUPInfo = dynamicShareItem.dynamicUPInfo;

    DynamicTopic? dynamicTopic = dynamicShareItem.dynamicTopic;
    List<DynamicLabel>? dynamicLabelList = dynamicShareItem.dynamicLabelList;
    String? content = dynamicShareItem.content;
    String dynamicType = dynamicShareItem.dynamicType;

    DynamicImageTextItem? dynamicImageTextItem =
        dynamicShareItem.dynamicImageTextItem;

    DynamicVideoItem? dynamicVideoItem = dynamicShareItem.dynamicVideoItem;
    DynamicArticleItem? dynamicArticleItem =
        dynamicShareItem.dynamicArticleItem;

    return Container(
      margin: const EdgeInsets.only(bottom: 10),
      padding: const EdgeInsets.fromLTRB(0, 8, 0, 8),
      decoration: const BoxDecoration(
        color: Color.fromARGB(255, 245, 245, 245),
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: [
          Padding(
            padding: const EdgeInsets.only(left: 10, right: 10, bottom: 8),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Expanded(
                  flex: 1,
                  child: Text(
                    "@${dynamicUPInfo.name}",
                    style: const TextStyle(
                        fontSize: 15, color: Color.fromARGB(255, 29, 95, 161)),
                  ),
                ),
                dynamicUPInfo.isSubscribe
                    ? const SizedBox.shrink()
                    : const Padding(
                        padding: EdgeInsets.only(right: 12),
                        child: Text(
                          '+ 关注',
                          style: TextStyle(
                            color: Color.fromARGB(255, 255, 126, 169),
                            fontSize: 14,
                          ),
                        ),
                      ),
              ],
            ),
          ),
          dynamicTopic != null
              ? Padding(
                  padding: const EdgeInsets.only(
                    bottom: 1,
                    left: 10,
                    right: 10,
                  ),
                  child: Row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Icon(
                        Icons.tag,
                        color: Colors.blue.shade600,
                      ),
                      Expanded(
                        flex: 1,
                        child: Text(
                          dynamicTopic.name,
                          maxLines: 1,
                          overflow: TextOverflow.ellipsis,
                          style: TextStyle(
                            color: Colors.blue.shade800,
                            fontSize: 16,
                          ),
                        ),
                      )
                    ],
                  ),
                )
              : const SizedBox(),
          dynamicLabelList != null && dynamicLabelList.isNotEmpty
              ? Padding(
                  padding: const EdgeInsets.only(
                    bottom: 10,
                    left: 10,
                    right: 10,
                  ),
                  child: Row(
                    children: dynamicLabelList.map((e) {
                      return Text(
                        "#${e.name}#",
                        style: TextStyle(
                          color: Colors.blue.shade800,
                          fontSize: 16,
                        ),
                      );
                    }).toList(),
                  ),
                )
              : const SizedBox(),
          content != null
              ? Padding(
                  padding: const EdgeInsets.only(
                    bottom: 10,
                    left: 10,
                    right: 10,
                  ),
                  child: Text(
                    content,
                    style: const TextStyle(
                      fontSize: 16,
                      color: Colors.black54,
                    ),
                  ),
                )
              : const SizedBox(),
          dynamicType == 'imageText' && dynamicImageTextItem != null
              ? DynamicImageListWidget(
                  dynamicImageTextItem: dynamicImageTextItem,
                )
              : const SizedBox(),
          dynamicType == 'video' && dynamicVideoItem != null
              ? DynamicVideoWidget(
                  dynamicVideoItem: dynamicVideoItem,
                )
              : const SizedBox(),
          dynamicType == 'article' && dynamicArticleItem != null
              ? DynamicArticleWidget(
                  dynamicArticleItem: dynamicArticleItem,
                )
              : const SizedBox(),
        ],
      ),
    );
  }
}
